import pygame
import mods.CrystalLib

f = pygame.font.Font('C:/Windows/Fonts/simhei.ttf',0x0e)
F = pygame.font.Font('C:/Windows/Fonts/simhei.ttf',0x12)
Title_line = pygame.font.Font('C:/Windows/Fonts/simhei.ttf', 0x18)
screen = None

def inits(winmain):
    global screen
    screen = winmain
    mods.CrystalLib.printm('Loading mod: printlib')

def OutTextxy(what, color=(0,0,255), place = ('center', 2)):
    text = f.render(what, True, color)
    RECT = (450 if place[0] == 'center' else 1210 if place[0] == 'right' else 50, 10 + mods.CrystalLib.cint(place[1] * 30))
    screen.blit(text, RECT)

def xyprint(what, color, place):
    text = F.render(what, True, color)
    RECT = (450 if place[0] == 'center' else 1210 if place[0] == 'right' else 50, 10 + mods.CrystalLib.cint(place[1] * 50))
    screen.blit(text, RECT)

def TitleBarPrint(what, color = (0, 255, 0)):
    text = Title_line.render(what, True, color)
    Rect = text.get_rect()
    Rect.center = (600, 450)
    screen.blit(text, Rect)

def CenterPrint(what, color, CenterPos : tuple, _screen_new = None):
    if _screen_new == None:
        _screen_new = screen
    text = F.render(what, True, color)
    REct = text.get_rect()
    REct.center = CenterPos
    _screen_new.blit(text, REct)

def CenterPrint1(what, color, CenterPos : tuple, _screen_new = None):
    if _screen_new == None:
        _screen_new = screen
    text = f.render(what, True, color)
    REct = text.get_rect()
    REct.center = CenterPos
    _screen_new.blit(text, REct)

def CreateButton(Rect, text, fg, bg, color = None, func = CenterPrint,  _screen_new = None):
    if _screen_new == None:
        _screen_new = screen
    if color == None:
        color = fg
    pygame.draw.rect(_screen_new, fg, Rect)
    pygame.draw.rect(_screen_new, bg, (Rect[0] + 5, Rect[1] + 5, Rect[2] - 10, Rect[3] - 10))
    func(text, color, (mods.CrystalLib.cint(Rect[0] + (Rect[2] / 2)), mods.CrystalLib.cint(Rect[1] + (Rect[3] / 2))), _screen_new)
